import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import render from '@dfeidao/atom-web/render/render';
import a012 from './a012';
import p015 from './p015';

export default async function a011(fd: IFeidaoAiBrowserComponent, list: Array<{ attr_no: string; flag?: boolean }>) {
	// todo
	const n = get(fd, 'data1') as Array<{ attr_no: string; flag?: boolean }>;
	if (!n) {
		render(fd, list, p015, 'p015', 'inner');
		set(fd, 'data1', list);
		await a012(fd);
	} else {
		list.forEach((v) => {
			const no = v.attr_no;
			const res = n.filter((d) => {
				return d.attr_no === no;
			});
			if (res.length === 0) {
				n.push(v);
			} else {
				for (let i = 0; i < n.length; i++) {
					const e = n[i];
					if (e.attr_no === no) {
						e.flag = true;
					}
				}
			}
			render(fd, n, p015, 'p015', 'inner');
			set(fd, 'data1', list);
		});

	}
	await a012(fd);
}
